#include <iostream>
#include <vector>
using namespace std;

class Solution2 {
public:
    int searchInsert(vector<int>& nums, int target) {
        int left = 0, right = nums.size() - 1;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] >= target)
                right = mid;
            else
                left = mid + 1;
        }
        if (nums[left] < target)
            return left + 1;
        return left;
    }
};

class Solution1 {
public:
    int mySqrt(int x)
    {
        if (x == 0)
            return 0;

        long long left = 0, right = x;
        while (left < right)
        {
            long long mid = left + (right - left + 1) / 2;
            if (mid * mid > x)
                right = mid - 1;
            else
                left = mid;
        }
        return left;
    }
};

int main()
{
    //cout << Solution1().mySqrt(200) << endl;
    Solution2();

    return 0;
}